package tt.dz.egobus.servicemanager.business.key;


import tt.dz.egobus.bean.Factory;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author Anson
 * @date 17-3-27
 * @name 业务id生成器
 *      6(businessCode) + 13(时间戳) + 5(随机数)
 * @since 1.0.3
 */
public final class CodeBusinessIdGenerator implements Factory<String> {

    private final int businessCode;

    private final ThreadLocalRandom random = ThreadLocalRandom.current();

    public CodeBusinessIdGenerator(int businessCode) {
        this.businessCode = businessCode;
    }

    @Override
    public String facorty() {
        return businessCode + (System.currentTimeMillis() + "") + this.randomInt();
    }

    /**
     * 创建随机数
     *
     * @return
     */
    private int randomInt() {
        return this.random.nextInt(10000, 99999) + 1;

    }

}
